local config = require "config"
SERVICE_D:register(
    config.server.game_channel,
    function(linda, bytes)
        local ok, name, data = PROTOCOL_D:decode(bytes)
        if not ok then
            return
        end

        if data.timestamp + 60 < os.time() then
            spdlog.warn("game_channel", string.format("member[timestamp] too long, data : %s", data))
            return
        end

        if not data.agent_id then
            spdlog.warn("game_channel", string.format("member[agent_id] type error, data : %s", data))
            return
        end

        local user_ob = LOGIN_D:find_user(data.agent_id)
        if not user_ob then
            -- spdlog.error("game_channel", string.format("not found userOb, clientId [%s] MsgType [%s]", clientId, recv.MsgType))
            -- LOGIN_D:kickout(clientAddr, clientId)
            return
        end

        if "tunnel.logoff" == name then
            ---! 玩家登出
            USER_D:disconnect(user_ob, 0)
            return
        end

        local ok, name, data = PROTOCOL_D:decode(data.bytes)
        if not ok then
            return
        end

        --[[
        if name ~= "tanker.C2SPlayInput" and name ~= "tanker.C2SPing" then
            print("receive_packet",name)
            dump(data)
        end
        --]]

        local size
        if bytes then
            size = #bytes
        else
            size = 0
        end

        COMMAND_D:process_command(user_ob, name, data, size)
    end
)
